package com.feige.mybatis;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 用于创建插入时间和修改时间
 * @author feige
 */
@Component
public class AutoFillHandler implements MetaObjectHandler {

    
    
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("gmtCreate", new Date(), metaObject);
        // TODO 未实现
        this.setFieldValByName("createdBy", "", metaObject);
        this.setFieldValByName("gmtModified", new Date(), metaObject);
        // TODO 未实现
        this.setFieldValByName("modifyBy", "", metaObject);
        this.setFieldValByName("deleted", 1, metaObject);
        this.setFieldValByName("version", 1, metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("gmtModified", new Date(), metaObject);
        // TODO 未实现
        this.setFieldValByName("modifyBy", "", metaObject);
    }
}
